using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class CheckEnemies : MonoBehaviour
{
    private bool canReset = false;
    public string tagTarget = "Enemy";
    public List<Collider2D> detectedObjs = new List<Collider2D>();
    Collider2D zone;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void FixedUpdate()
    {
        if(detectedObjs.Count <= 0  && canReset)
        {
            print("KONEC");
            SceneManager.LoadScene("continue");
        }
    }

    void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.gameObject.tag == tagTarget)
        {
            detectedObjs.Add(collider);
        }
    }

    void OnTriggerExit2D(Collider2D collider)
    {
        if(collider.gameObject.tag == tagTarget)
        {
            detectedObjs.Remove(collider);
        }
        if (detectedObjs.Count <= 0) canReset = true;
    }
}
